/*
 * @Descripttion: toolkit的createAction方法
 * @Author: lukasavage
 * @Date: 2021-12-07 20:18:58
 * @LastEditors: lukasavage
 * @LastEditTime: 2021-12-07 21:01:37
 */
/**
 * 用于简化生成action的工厂函数方法
 * @param {*} type 代表action对象
 * @param {*} prepareAction 一个函数用于改写(预处理)payload
 * @returns action工厂函数
 */
function createAction(type, prepareAction) {
    function actionCreator(args) {
        if (prepareAction) {
            let prepared = prepareAction(args);
            return {
                type,
                ...prepared,
            }
        }
        return {
            type,
            payload: args
        }
    }
    actionCreator.type = type;
    return actionCreator;
}

export default createAction;


